package com.beemans.common.ext.glide

import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.target.Target
import com.tiamosu.fly.imageloader.glide.ImageConfigImpl

/**
 * @author tiamosu
 * @date 2021/4/8.
 */
class GlideCallback<T> {
    internal var options: ((ImageConfigImpl.Builder).() -> Unit)? = null

    internal var onSuccess: ((
        resource: T?,
        model: Any?,
        target: Target<T>?,
        dataSource: DataSource?,
        isFirstResource: Boolean
    ) -> Unit)? = null

    internal var onFail: ((
        e: GlideException?,
        model: Any?,
        target: Target<T>?,
        isFirstResource: Boolean
    ) -> Unit)? = null

    internal var onComplete: ((
        resource: T?,
        e: GlideException?,
        model: Any?,
        target: Target<T>?,
        dataSource: DataSource?,
        isFirstResource: Boolean
    ) -> Unit)? = null

    fun options(options: (ImageConfigImpl.Builder).() -> Unit) {
        this.options = options
    }

    fun onSuccess(
        onSuccess: (
            resource: T?,
            model: Any?,
            target: Target<T>?,
            dataSource: DataSource?,
            isFirstResource: Boolean
        ) -> Unit
    ) {
        this.onSuccess = onSuccess
    }

    fun onFail(
        onFail: (
            e: GlideException?,
            model: Any?,
            target: Target<T>?,
            isFirstResource: Boolean
        ) -> Unit
    ) {
        this.onFail = onFail
    }

    fun onComplete(
        onComplete: (
            resource: T?,
            e: GlideException?,
            model: Any?,
            target: Target<T>?,
            dataSource: DataSource?,
            isFirstResource: Boolean
        ) -> Unit
    ) {
        this.onComplete = onComplete
    }
}